package StudyCode.summary.mycollection;

import java.util.ArrayList;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class RandomlyPermutesAllEntriesInAnArrayList {
	public static <T extends Comparable<? super T>> void shuffle(
			ArrayList<T> arrayList) {
		for (int i = 0; i < arrayList.size(); i++) {
			swap(arrayList, i, (int) (Math.random() * arrayList.size()));
		}
	}


	public static <T extends Comparable<? super T>> void swap(
			ArrayList<T> arrayList, int yin, int yang) {
		T qi = arrayList.get(yin);
		arrayList.set(yin, arrayList.get(yang));
		arrayList.set(yang, qi);
	}
}
